package com.doophan.duuchin.service.impl;

import com.doophan.duuchin.dto.PageDTO;
import com.doophan.duuchin.dto.QueryDTO;
import com.doophan.duuchin.mapper.UserMapper;
import com.doophan.duuchin.model.User;
import com.doophan.duuchin.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public PageDTO<User> getList(QueryDTO queryDTO) {
        PageHelper.startPage(queryDTO.getPage(), queryDTO.getLimit());
        List<User> userList = userMapper.selectList(null);
        PageInfo pageInfo = new PageInfo<>(userList);
        PageHelper.clearPage();
        PageDTO pageDTO = PageDTO.builder().total(pageInfo.getTotal()).data(pageInfo.getList()).build();
        return pageDTO;
    }

    @Override
    public User getInfo(Integer id) {
        return userMapper.selectById(id);
    }
}
